package com.situ.system.performance.service;

import java.util.List;

import com.situ.system.performance.dao.PerformanceDao;
import com.situ.system.performance.model.PerformanceModel;

public class PerformanceService {
	PerformanceDao dao = new PerformanceDao();

	public String insert(PerformanceModel model) {
		PerformanceModel model2 = new PerformanceModel(model.getE_id());
		List<PerformanceModel> list = selectList(model2);
		System.out.println(list);
		if (list == null || list.isEmpty()) {
			return dao.insert(model);
		} else {
			return "-1";
		}
	}

	public String delete(PerformanceModel model) {
		return dao.delete(model);
	}

	public String updata(PerformanceModel model) {
		return dao.updata(model);
	}

	public List<PerformanceModel> selectList(PerformanceModel model) {
		String performanceE_id = model.getE_id();
		String performanceP_id = model.getP_id();
		if (performanceE_id == null || performanceE_id.trim().isEmpty()) {
			performanceE_id = "";
		}
		if (performanceP_id == null || performanceP_id.trim().isEmpty()) {
			performanceP_id = "";
		}
		model.setE_id("%" + performanceE_id + "%");
		model.setP_id("%" + performanceP_id + "%");

		List<PerformanceModel> list = dao.select(model);
		return list;
	}

	public Integer selectCount(PerformanceModel model) {
		PerformanceModel model2 = new PerformanceModel();
		String performanceE_id = model.getE_id();
		String performanceP_id = model.getP_id();
		if (performanceE_id == null || performanceE_id.trim().isEmpty()) {
			performanceE_id = "";
		}
		if (performanceP_id == null || performanceP_id.trim().isEmpty()) {
			performanceP_id = "";
		}
		model2.setE_id("%" + performanceE_id + "%");
		model2.setP_id("%" + performanceP_id + "%");

		return dao.selectCount(model2);
	}

	public PerformanceModel selectModel(PerformanceModel model) {
		List<PerformanceModel> list = selectList(model);
		if (list == null) {
			return null;
		} else {
			return list.get(0);
		}
	}
}
